home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 October / CMCD1004.ISO / Software / Shareware / Programare / gpssdk / GPS.NET Global Positioning SDK 1.4.6.msi / Data1.cab / NewWaypointForm.vb4 < prev    next >
Encoding:
Text File  |  2004-08-24  |  5.4 KB  |  114 lines

  1. ∩╗┐Imports StormSource.Gps
  2.  
  3. Public Class NewWaypointForm
  4.  
  5.     ' Stores information about a GPS device
  6.     Private WithEvents pDevice As Device
  7.  
  8.     ' Returns/sets the device containing waypoint information
  9.     Public Property Device() As Device
  10.         Get
  11.             Return pDevice
  12.         End Get
  13.         Set(ByVal Value As Device)
  14.             ' Remember the waypoint for editing later on
  15.             pDevice = Value
  16.  
  17.             ' Populate the combo box with the list of available waypoint symbols
  18.             WaypointSymbolComboBox.Items.Clear()
  19.             WaypointSymbolComboBox.Items.AddRange(pDevice.GetSymbols)
  20.             WaypointSymbolComboBox.SelectedIndex = WaypointSymbolComboBox.FindString("Dot")
  21.  
  22.             ' Populate the color combo box with the list of available waypoint symbols
  23.             WaypointColorComboBox.Items.Clear()
  24.             WaypointColorComboBox.Items.AddRange(pDevice.GetColors)
  25.             WaypointColorComboBox.SelectedIndex = WaypointColorComboBox.FindString("Default")
  26.  
  27.             ' Populate the display mode box with the list of available waypoint symbols
  28.             WaypointDisplayModeComboBox.Items.Clear()
  29.             WaypointDisplayModeComboBox.Items.AddRange(pDevice.GetDisplayModes)
  30.             WaypointDisplayModeComboBox.SelectedIndex = WaypointDisplayModeComboBox.FindString("SymbolOnly")
  31.  
  32.             ' Now, enable/disable features based on the capabilities of the device
  33.             Description.Enabled = pDevice.SupportsWaypointComment
  34.             Address.Enabled = pDevice.SupportsWaypointAddress
  35.             WaypointSymbolComboBox.Enabled = pDevice.SupportsWaypointSymbol
  36.             WaypointColorComboBox.Enabled = pDevice.SupportsWaypointColor
  37.             WaypointDisplayModeComboBox.Enabled = pDevice.SupportsWaypointDisplayMode
  38.             Facility.Enabled = pDevice.SupportsWaypointFacility
  39.             Address.Enabled = pDevice.SupportsWaypointAddress
  40.             City.Enabled = pDevice.SupportsWaypointCity
  41.             State.Enabled = pDevice.SupportsWaypointState
  42.             Country.Enabled = pDevice.SupportsWaypointCountry
  43.             IntersectingRoad.Enabled = pDevice.SupportsWaypointIntersectingRoad
  44.         End Set
  45.     End Property
  46.  
  47.     Private Sub SaveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveButton.Click
  48.         Dim NewWaypoint As Waypoint
  49.         ' Now set the waypoint's properties
  50.         Try
  51.             ' Create a new waypoint 
  52.             NewWaypoint = New Waypoint()
  53.             ' Update the waypoint with values from the form
  54.             NewWaypoint.Name = Me.WaypointName.Text
  55.             ' Update the position
  56.             Dim NewPosition As Position = StormSource.Gps.Position.Parse(Position.Text)
  57.             NewWaypoint.Latitude = NewPosition.Latitude
  58.             NewWaypoint.Longitude = NewPosition.Longitude
  59.             ' Update the comment
  60.             NewWaypoint.Description = Me.Description.Text
  61.             ' Update the symbol
  62.             NewWaypoint.Symbol = System.Enum.Parse(GetType(WaypointSymbol), WaypointSymbolComboBox.Text)
  63.             ' Update the color
  64.             NewWaypoint.Color = System.Enum.Parse(GetType(WaypointColor), WaypointColorComboBox.Text)
  65.             ' Update the symbol
  66.             NewWaypoint.DisplayMode = System.Enum.Parse(GetType(WaypointDisplayMode), WaypointDisplayModeComboBox.Text)
  67.             ' Update the altitude
  68.             Dim NewAltitude As Distance = Distance.Parse(Me.Altitude.Text)
  69.             NewWaypoint.Altitude = NewAltitude
  70.             ' Update the depth
  71.             Dim NewDepth As Distance = Distance.Parse(Me.Depth.Text)
  72.             NewWaypoint.Depth = NewDepth
  73.             ' Update the facility
  74.             NewWaypoint.Facility = Me.Facility.Text
  75.             ' Update the address
  76.             NewWaypoint.Address = Me.Address.Text
  77.             NewWaypoint.City = Me.City.Text
  78.             NewWaypoint.State = Me.State.Text
  79.             NewWaypoint.Country = Me.Country.Text
  80.             ' Update the intersecting road/intersection
  81.             NewWaypoint.IntersectingRoad = Me.IntersectingRoad.Text
  82.         Catch ex As Exception
  83.             ' Some error occurred while try to update waypoint information
  84.             MessageBox.Show(ex.Message, "Form Information is Invalid", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  85.             Exit Sub
  86.         End Try
  87.         Try
  88.             ' Tell the waypoint which kind of GPS device to use
  89.             NewWaypoint.Device = Me.Device
  90.             ' Save this waypoint to the device
  91.             NewWaypoint.Save()
  92.             ' Refresh the waypoints collection
  93.             NewWaypoint.Device.Receiver.Waypoints.Refresh()
  94.             ' And unload this form
  95.             Close()
  96.         Catch ex As Exception
  97.             ' Notify of the problem saving the waypoint
  98.             MessageBox.Show(ex.Message, "Unable to Create Waypoint", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  99.             Exit Sub
  100.         End Try
  101.     End Sub
  102.  
  103.     ' Raised when editing of a waypoint has been cancelled
  104.     Private Sub btnCancelButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelButton.Click
  105.         Close()
  106.     End Sub
  107.  
  108.     ' Raised when the device becomes identified
  109.     Private Sub pDevice_DeviceIdentified(ByVal sender As Object, ByVal e As StormSource.Gps.DeviceEventArgs) Handles pDevice.DeviceIdentified
  110.         Me.Device = e.Device
  111.     End Sub
  112.  
  113. End Class
  114.